package com.boful.convert.core.impl;

import java.io.File;

import org.apache.log4j.Logger;

import com.boful.convert.core.TranscodeEvent;
import com.boful.convert.core.impl.utils.FFMpegUtils;
import com.boful.convert.model.DiskFile;
import com.boful.convert.utils.MediaInfo;

class AudioConvert {
	private static Logger logger = Logger.getLogger(AudioConvert.class);
	private String ffmpegPath;

	private String mediaInfoPath;

	public AudioConvert(String ffmpegPath, String mediaInfoPath) {
		super();
		this.ffmpegPath = ffmpegPath;
		this.mediaInfoPath = mediaInfoPath;
	}

	public AudioConvert() {
	}

	protected void convert(DiskFile src, DiskFile dest, int audioBitrate,
			TranscodeEvent transcodeEvent,String jobId) {
		try {
			MediaInfo mediaInfo = new MediaInfo(new File(getMediaInfoPath()), src);
			FFMpegUtils.transcode(ffmpegPath,
					mediaInfoPath, src.getAbsolutePath(), dest.getAbsolutePath(), -1, -1, null, null, null, -1, mediaInfo.getAudioInfo().getBitRate(), mediaInfo.getAudioInfo().getChannel(), -1, null, transcodeEvent, jobId);
		} catch (Exception e) {
			if (transcodeEvent != null) {
				logger.error(e);
				transcodeEvent.onTranscodeFail(src, e.getMessage(),jobId);
			}
		}
	}

	public String getFfmpegPath() {
		return ffmpegPath;
	}

	public String getMediaInfoPath() {
		return mediaInfoPath;
	}

	public void setFfmpegPath(String ffmpegPath) {
		this.ffmpegPath = ffmpegPath;
	}

	public void setMediaInfoPath(String mediaInfoPath) {
		this.mediaInfoPath = mediaInfoPath;
	}

}
